<template>
	<div>
    <Breadcrumb :style="{margin: '15px 0',float: 'left'}">
      <BreadcrumbItem>首页</BreadcrumbItem>
      <BreadcrumbItem>村庄管理</BreadcrumbItem>
      <BreadcrumbItem>村集体</BreadcrumbItem>
    </Breadcrumb>
    <Content class="layer-content">
      <Form inline>
        <FormItem>
          <Input style="width: 500px" v-model="keywords" search enter-button placeholder="请输入关键字" @on-search="doSearch" @submit.native.prevent/>
        </FormItem>
        <FormItem>
          <Select style="width:120px" placeholder="审核状态" clearable @on-change="selectAudit">
            <Option :value="1">待审核</Option>
            <Option :value="2">审核通过</Option>
            <Option :value="3">驳回</Option>
          </Select>
        </FormItem>
        <FormItem>
          <Button @click="reset">重置</Button>
        </FormItem>
      </Form>
      <Table border :columns="columns" :data="dataGrid"></Table>
      <HigPager v-model="query" :total="pageTotal" :init="Init"></HigPager>
    </Content>
    
    <Modal :footer-hide="true" v-model="dialogVisible" title="村集体详情" width="70%">
        <div class="layer_top">
          <div class="name-area"> <span class="names">村集体名称：</span>{{ objDate.orgName }}</div>
          <div class="name-area"><span class="names">审核状态：</span>{{ objDate.auditText }}</div>
          <div class="name-area"><span class="names">联系人：</span>{{ objDate.contactName }}</div>
          <div class="name-area"><span class="names">联系电话：</span>{{ objDate.contactMobile }}</div>
          <div class="name-area"><span class="names">申请时间：</span>{{ objDate.postTime }}</div>
          <div class="name-area"><span class="names">组织类型：</span>{{ objDate.mchTypeText }}</div>
          <div class="name-area">
            <span class="names">所在地区：</span>
            {{objDate.provinceName}} 
            {{objDate.cityName}} 
            {{objDate.countyName}} 
            {{ objDate.townshipName }}
          </div>
          <div class="name-area"><span class="names">详细地址：</span>{{ objDate.addressDetail }}</div>
        </div>
        <div style="margin-top: 20px">
          <span class="yings">营业执照:</span>
          <img class="imgs" :src="objDate.bizLicImage" alt="">
          <span class="yings">授权书:</span>
          <img class="imgs" :src="objDate.certificateSrc" alt="">
          <span class="yings">身份证照片:</span>
          <img class="imgs" :src="objDate.idCardFront" alt="">
          <span class="yings"> 身份证照片:</span>
          <img class="imgs" :src="objDate.idCardBack" alt="">
        </div>
        <Input v-model="dataForm.auditNotes" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="审核备注" />
        <div class="middle_btn">
          <Button v-if="isAudit" type="primary" @click="Submit(2)">通过</Button>
          <Button v-if="isAudit" type="default" @click="Submit(3)">驳回</Button>
        </div>
      </Modal>
  </div>
</template>

<script scope>
export default {
  data () {
    return {
      objDate:{},
      isPass: true,
      isAudit: false,
      pageTotal: 0,
      dialogVisible: false,
      keywords: null,
      dataGrid:[],
      dataForm: {
        userType: 8, //8村集体
        auditNotes: null,
        orgId: null,
        auditorOrgId: this.$store.getOrg('orgId')
      },
      query: {
        pageIndex: 1,
        pageSize: 15,
        equal: {
          orgType: 2,
          appType: 0
        }
      },
      columns: [
        {
          title: "村集体名称",
          key: "orgName",
        },
        {
          title: "联系人",
          key: "contactName",
        },
        {
          title: "联系电话",
          key: "contactMobile",
        },
        {
          title: "审核状态",
          key: "auditText",
        },
        {
          title: "审核时间",
          key: "auditTime",
        },
        {
          title: "申请时间",
          key: "postTime",
        },
        {
          title: "操作",
          key: "action",
          width: 140,
          render: (h, params) => {
            return h("nav", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small",
                    disabled: params.row.orgStatus !== 1,
                  },
                  on: {
                    click: () => {
                      this.btnSee(params.row,true)
                    },
                  },
                },
                "审核"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "default",
                    size: "small",
                  },
                  style: {
                    marginLeft: "10px",
                  },
                  on: {
                    click: () => {
                      this.btnSee(params.row,false)
                    },
                  },
                },
                "查看"
              )
            ])
          },
        },
      ]
    }
  },
  methods: {
    //审核
    Submit(status){
      this.dataForm.orgStatus = status
      new this.$rest({
        gateway: 'agrobiz',
        service: "agrobiz-uc",
        url: "/v1.0/plus/audit/user/org",
        data: {
          pojo: this.dataForm
        },
        action: (res) => {
          if (res.data.code === 20000) {
            this.$Message.success({
              content: '操作成功',
              duration: 1,
              onClose: ()=> {
                this.dialogVisible = false
              }
            })
            this.Init()
          } else {
            this.$Notice.warning({
              desc: `失败原因：${res.data.msg}`,
            });
          }
        },
      }).post()
    },
    selectAudit(status) {
      if(!this.query.equal) this.query.equal = new Object()
      this.query.equal.orgStatus = status
      this.Init()
    },
    doSearch() {
      let sqlLike = {
        fields: ["org_name", "legal_mobile","legal_person","contact_mobile","union_credit_code"],
        keyword: this.keywords,
      }
      this.query.sqlLike = sqlLike
      this.query.pageIndex = 1
      this.Init()
    },
    reset() {
      delete this.query.sqlLike
      if(this.query.equal) delete this.query.equal.orgStatus
      this.keywords = null
      this.Init()
    },
    //获取列表
    Init(){
      new this.$rest({
        service: 'agrobiz-uc',
        gateway: 'agrobiz',
        url: '/v1.0/view/org/info/page',
        query: this.query,
        action: (res) => {
          if (res.data.code === 20000) {
            this.pageTotal = res.data.data.count
            this.dataGrid = res.data.data.list
            for(let item of this.dataGrid) {
              item.postTime = this.$date(item.postTime,'yyyy-MM-dd HH:mm:ss')
              if(item.auditTime) item.auditTime = this.$date(item.auditTime,'yyyy-MM-dd HH:mm:ss')
              if(item.orgStatus === 1) {
                item.auditText = '待审核'
              } else if (item.orgStatus === 2) {
                item.auditText = '审核通过'
              } else if (item.orgStatus === 3) {
                item.auditText = '驳回'
              } else {
                item.auditText = '草稿'
              }
            }
          } else {
            this.$Message.error(res.data.msg)
          }
        }
      }).get()
     },
    //查看
    btnSee(e,bool){
      this.objDate = e
      this.dataForm.orgId = e.orgId
      this.dataForm.auditNotes = e.auditNotes
      this.objDate.mchTypeText = this.$enum.mchType(e.orgType)
      this.dialogVisible = true
      this.isAudit = bool
    }
  },
  created(){
    this.Init()
  }
}
</script>
<style lang="less" scoped>
.layer_top {
  display: flex; flex-wrap: wrap;
}
.name-area {
  padding: 3px 0; width: 33%;
}
.names {
  width: 100px; font-weight: 800; display: inline-block;
}
.imgs {
  width: 100px;
}
.yings {
  vertical-align: top;
}
</style>